home > .cgi > Adding a chatroom

 

.home
.news
.sites
.free downloads
.tips & tricks
.web builder
.cgi
.intro to Perl
.your own server
.add a chatroom
.uploading CGI
.bughunting
.using PWS
.smart ass
.resources
.in-depth articles
.magazine
.forums
.contacts
.site map
.IE5 companion
.cgi
Need to supercharge your Web site? Got a database of products, and no way to get them online. You need to harness the power of CGI programming. Using languages such as Perl, ASP and PHP, you can create interactive, intelligent sites. This is part one of the series that appeared in .net magazine. Subscribe now so you don't any of the upcoming articles!
 

Continued...

Getting chatty

Now it's time to get Perl doing something useful. We're going to add a simple chat room to our Web site, using a free program called EveryChat. If you've got last month's CD, you'll find it there, or you can download it from www.everysoft.com/everychat. Copy the Zip file to your hard drive and extract the files using WinZip or a similar zip program.

Now take a look in the folder you installed Xitami to - it'll normally be C:\Xitami. You'll notice a bunch of folders inside it. The two important ones are the cgi-bin folder and the webpages folder. Copy the evercht.cgi file from zip to your cgi-bin, then create a new folder inside webpages. Call it chat, and make another folder inside it called messages.

Copy chatform.html, chatframes.html and chattop.html to the chat folder, then copy messages.html to the messages subfolder. Open chatforms.html in Notepad and find the '<FORM ACTION=..' line. Change the address to '/cgi-bin/everycht.cgi'. Do the same to chatframes.html.

When you give a URL starting with a forward slash, the Web server starts at the 'top' of your Web site (the root), and works down from there. In Xitami, this root is the webpages directory. But the cgi-bin is a bit special. Even though it's above the root on your hard drive, the server creates a 'virtual' directory inside the root. This is done for security reasons.

Now open everycht.cgi with Notepad. Be careful about using other text editors with Perl scripts - some, such as Word, leave garbage at the ends of the lines that will stop them being read correctly. Notepad might not be pretty, but it doesn't mess with things.

Scroll down until you get to the section marked 'CONFIGURATION'. You'll see an indented line starting '$filepath='. Replace the text between the quotes with full path to your new messages directory from the root of your drive - it should be something like: '/Xitami/webpages/chat/messages/'. Notice we've used forward slashes all the way through, and added one to the end.

Because Perl programs run on the server directly, instead of through a Web server like Xitami, their 'root' is at the top of your host's directory structure, not the Web server's. It's important to remember this when it comes time to upload your CGI programs. The actual location of your cgi-bin directory will vary depending on how your host has their server configured. Check their help pages or use the test-perl.pl script, as described in Uploading your Chat Room, and change the $filepath line accordingly.

Click to view full size

If you ever need to change the directories Xitami stores your Web site in, take a look at the setup pages at http://127.0.0.1/admin

Getting it to work

Now point your browser at http://127.0.0.1/chat/chatframes.html. Give yourself a name and click Submit Name button. Once the centre screen refreshes, you'll see your name enter the chat room, and you're away.

The script doesn't produce the prettiest chat room going, but there's lots of ways you can customise it before letting it lose on the world. Tale a look through the Readme.txt file that came with EveryChat for some ideas. We're going plough on and upload it, however. See Uploading your Chat Room to learn how it's done.

Once you've got the basics down, check out the other sections in this article: Bughunting - for when things go wrong, Smartass - for the lowdown on CGI jargon and Resources - for links to great Perl sites.

Next month, we'll go into more detail about how Perl scripts are put together so you can start getting your hands dirty in the code. Until then, happy Perl Mongering.


Matt Kynaston
is Deputy Editor of Internet.Works


 1  2  3   

click here for print version of this story.






|.home|.news|.sites|.free downloads|.tips & tricks|.web builder|.in-depth articles|.magazine|.forums|.contacts|.sitemap|
Copyright Future Publishing 2001. All rights reserved. Reproduction in whole or in part in any form or medium without express written permission from Future Publishing is prohibited. If you have any questions relating to the site, please contact the webmaster.
Click here for our Privacy statement.